#include "stdafx.h"
#include "TestSelectorTable.h"
#include "DatabaseBase.h"
#include "UeConnectionManager.h"
#include "SelectorTable.h"

using namespace PDMS::PDMSDBIF;


CPPUNIT_TEST_SUITE_REGISTRATION( TestSelectorTable );


TestSelectorTable::TestSelectorTable()
{
}


TestSelectorTable::~TestSelectorTable()
{

}

void TestSelectorTable::TestInsert()
{
	DatabaseBase base( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	SelectorTable* pSelectorTable = NULL;
	base.DataSource( _T("D:\\SpecificationTemplate.mdb") );
	DatabaseElement* p = base.GetDatabaseElement( _T("selector") );

	if (p->IsKindOf( UE_RUNTIME_CLASS( SelectorTable ) ) )
	{
		pSelectorTable = static_cast<SelectorTable*>( p );
	}

	UESoft::ErrorStatus es = pSelectorTable->Open();
	ASSERT( es == UESoft::eOk );
	
	pSelectorTable->NewRecord();
	pSelectorTable->SetID( 10101 );
	pSelectorTable->SetParentID( 23689 );
	pSelectorTable->SetName(_T("China") );
	pSelectorTable->SetSpecName( _T("Hunan") );
	pSelectorTable->SetAllo( TRUE );
	pSelectorTable->SetAngle( 90.0 );
	pSelectorTable->SetShop( FALSE );
	pSelectorTable->SetPbor0(10.5 );
	pSelectorTable->SetPbor1( 5.63 );
	pSelectorTable->SetPbor2( 152.36 );
	pSelectorTable->SetPbor3( 45.365 );
	pSelectorTable->SetSCOMID( 1000 );

	pSelectorTable->Update();
	pSelectorTable->Close();
	UEConnectionManager::Instance().CloseAllConnection();
}

void TestSelectorTable::TestDelete()
{
	DatabaseBase base( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	SelectorTable* pSelectorTable = NULL;
	base.DataSource( _T("D:\\SpecificationTemplate.mdb") );
	DatabaseElement* p = base.GetDatabaseElement( _T("selector") );

	if (p->IsKindOf( UE_RUNTIME_CLASS( SelectorTable ) ) )
	{
		pSelectorTable = static_cast<SelectorTable*>( p );
	}

	UESoft::ErrorStatus es = pSelectorTable->Open();
	ASSERT( es == UESoft::eOk );

	pSelectorTable->DeleteRecord( 101 );
	
	pSelectorTable->Update();
	pSelectorTable->Close();
	UEConnectionManager::Instance().CloseAllConnection();
}

void TestSelectorTable::TestUpdate()
{
	DatabaseBase base( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	SelectorTable* pSelectorTable = NULL;
	base.DataSource( _T("D:\\SpecificationTemplate.mdb") );
	DatabaseElement* p = base.GetDatabaseElement( _T("selector") );

	if (p->IsKindOf( UE_RUNTIME_CLASS( SelectorTable ) ) )
	{
		pSelectorTable = static_cast<SelectorTable*>( p );
	}

	UESoft::ErrorStatus es = pSelectorTable->Open();
	ASSERT( es == UESoft::eOk );

	pSelectorTable->UpdateRecord( 10101 );
	pSelectorTable->SetID( 10101 );
	pSelectorTable->SetName( _T("USA") );
	
	pSelectorTable->Update();
	pSelectorTable->Close();
	UEConnectionManager::Instance().CloseAllConnection();
}